<?php

namespace App\Http\Controllers\Api;

use App\Enum\RedisEnum;
use Illuminate\Http\Request;
use App\Enum\CodeEnum;
use App\Services\TravelAddressService;

class TravelAddressController extends ApiBaseController
{
    /**
     * 常用地址
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\JsonResponse
     * @author ninetyseven.
     * @date 2023-04-03 23:35
     */
    public function getTravelAddress(Request $request): \Illuminate\Http\JsonResponse
    {
        try {
            $redisKey = sprintf(RedisEnum::R_CACHEABLE_KEY,'travel_address', $request->userId);
            $res = self::_cacheableData($redisKey, RedisEnum::R_CACHEABLE_TO,(new TravelAddressService()), 'getTravelAddress', $request->userId, $request,true);
//            $res = TravelAddressService::getTravelAddress($request ->userId);
            return success($res);
        } catch (\Exception $e) {
            return fail(CodeEnum::ERROR, $e->getMessage());
        }
    }

    /**
     * 添加地址
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\JsonResponse
     * @author ninetyseven.
     * @date 2023-04-03 23:35
     */
    public function addTravelAddress(Request $request): \Illuminate\Http\JsonResponse
    {
        try {
            $res = TravelAddressService::addTravelAddress($request);
            return success($res);
        } catch (\Exception $e) {
            return fail(CodeEnum::ERROR, $e->getMessage());
        }
    }
}
